home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1865 / 1865.xpi / chrome / adblockplus.jar / content / ui / flasher.js < prev    next >
Text File  |  2010-01-07  |  3KB  |  105 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Adblock Plus.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Wladimir Palant.
  18.  * Portions created by the Initial Developer are Copyright (C) 2006-2009
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * ***** END LICENSE BLOCK ***** */
  24.  
  25. /**
  26.  * Draws a blinking border for a list of matching nodes.
  27.  */
  28.  
  29. var flasher = {
  30.     nodes: null,
  31.     count: 0,
  32.     timer: null,
  33.  
  34.     flash: function(nodes) {
  35.         this.stop();
  36.         if (!nodes || !nodes.length)
  37.             return;
  38.  
  39.         if (prefs.flash_scrolltoitem && ("document" in nodes[0] || nodes[0].ownerDocument)) {
  40.             // Ensure that at least one node is visible when flashing
  41.             var wnd = ("document" in nodes[0] ? nodes[0] : nodes[0].ownerDocument.defaultView);
  42.             try {
  43.                 var viewer = wnd.QueryInterface(Ci.nsIInterfaceRequestor)
  44.                                                 .getInterface(Ci.nsIWebNavigation)
  45.                                                 .QueryInterface(Ci.nsIDocShellTreeItem)
  46.                                                 .rootTreeItem
  47.                                                 .QueryInterface(Ci.nsIInterfaceRequestor)
  48.                                                 .getInterface(Ci.nsIDOMWindow)
  49.                                                 .document.getElementById("abp-hooks")
  50.                                                 .wrappedJSObject
  51.                                                 .getBrowser()
  52.                                                 .markupDocumentViewer;
  53.                 viewer.scrollToNode(nodes[0]);
  54.             } catch(e) {}
  55.         }
  56.  
  57.         this.nodes = nodes;
  58.         this.count = 0;
  59.  
  60.         this.doFlash();
  61.     },
  62.  
  63.     doFlash: function() {
  64.         if (this.count >= 12) {
  65.             this.stop();
  66.             return;
  67.         }
  68.  
  69.         if (this.count % 2)
  70.             this.switchOff();
  71.         else
  72.             this.switchOn();
  73.  
  74.         this.count++;
  75.  
  76.         this.timer = window.setTimeout(function() {flasher.doFlash()}, 300);
  77.     },
  78.  
  79.     stop: function() {
  80.         if (this.timer) {
  81.             window.clearTimeout(this.timer);
  82.             this.timer = null;
  83.         }
  84.  
  85.         if (this.nodes) {
  86.             this.switchOff();
  87.             this.nodes = null;
  88.         }
  89.     },
  90.  
  91.     setOutline: function(value) {
  92.         for (var i = 0; i < this.nodes.length; i++)
  93.             if ("style" in this.nodes[i])
  94.                 this.nodes[i].style.outline = value;
  95.     },
  96.  
  97.     switchOn: function() {
  98.         this.setOutline("#CC0000 dotted 2px");
  99.     },
  100.  
  101.     switchOff: function() {
  102.         this.setOutline("none");
  103.     }
  104. };
  105.